<!--
 * @Author: 陈鹏新 cpx15004862443@qq.com
 * @Date: 2025-09-11 08:40:10
 * @LastEditors: 陈鹏新 cpx15004862443@qq.com
 * @LastEditTime: 2025-09-17 08:34:03
 * @FilePath: \前端\city\src\pages\components\Bottom3.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div>
        <Title :title="title"></Title>
        {{ ed }}
        <div ref="bottom3" style="height: 150px;"></div>
    </div>
</template>
<script>
import { DualAxes } from '@antv/g2plot';
import moment from 'moment';
import { get } from '@/utils/request'
import { mapState } from 'vuex';
export default {
    data() {
        return {
            title: '实时颗粒物曲线',
            params: {
                page: 1,
                pageSize: 100
            },
            kData: [],
            dualAxes: null,
        }
    },
    computed: {
        ...mapState(['ed'])
    },
    watch: {
        ed: {
            handler(n, o) {
                // 根据设备信息重新查询数据 重新渲染图表 
                this.params.engineer_id = n.engineer_id;
                this.params.device_id = n.device_id;
                this.getKData();
                // 根据最新获取的数据重新渲染图表 
                this.dualAxes.changeData([this.kData, this.kData]);
            },
            // 深度监听 
            deep: true
        }
    },
    methods: {
        loadDualAxes() {
            this.dualAxes = new DualAxes(this.$refs.bottom3, {
                data: [this.kData, this.kData],
                xField: 'insert_time',
                yField: [ 'pm25','pm10'],
                geometryOptions: [
                    {
                        geometry: 'column',
                    },
                    {
                        geometry: 'line',
                        lineStyle: {
                            lineWidth: 2,
                        },
                    },
                ],
            });
            this.dualAxes.render();
        },
        async getKData() {
            let res = await get('/dashboard/pageQueryData', this.params);
            console.log(res, '11111');
            let temp = [];
            // 将后端获取的数据设置给tempData 
            res.data.list.forEach((item, index, arr) => {
                 
                arr[0].pm25 = 200;
                arr[0].pm10=60;
                // item表示数组每一项 
                item.insert_time = moment(item.insert_time).format("HH:mm");
                // 由于查询数据密度密集 需要将数据处理 每隔10条数据取一条数据 
                if (index % 10 == 0) {
                    temp.push(arr[index])
                }
            });
            this.kData = temp;
        },
    },
    async mounted() {
        await this.getKData();
        this.loadDualAxes();
    },
}
</script>
<style lang="less" scoped></style>